<include file="Public:header" />
<script type="text/javascript" src="__PUBLIC__/js/kindeditor-all-min.js"></script>
<script type="text/javascript" src="__PUBLIC__/js/zh_CN.js"></script>
<script src="__PUBLIC__/js/PCASClass.js" type="text/javascript"></script>
<script type="text/javascript" src="__PUBLIC__/js/formValidator-4.0.1.min.js" charset="UTF-8"></script>
<script type="text/javascript" src="__PUBLIC__/js/formValidatorRegex.js" charset="UTF-8"></script>
<link rel="stylesheet" href="__PUBLIC__/css/kindeditor.css" type="text/css" />
<link rel="stylesheet" href="__PUBLIC__/css/jquery.fileupload.css" type="text/css" />
<div class="container">
    <!-- Docs nav ================================================== -->
    <div class="page-header">
        <h4>添加试吃</h4>
    </div>
    <div class="row">
        <div class="span12">
            <include file="Public:alert" />
        </div>
        <div class="span12">
            <form id="form1" action="{:U('taste/add')}" method="post" enctype="multipart/form-data">
                <input type='hidden' name="customer_id" value="{$customer['customer_id']}"/>
                <table class="table" width="95%" border="0" cellspacing="1" cellpadding="0">
                    <tfoot>
                    <tr>
                        <td style="text-align:center;" colspan="4">
                            <input name="submit" class="btn btn-primary" type="submit" value="{:L('SAVE')}"/>&nbsp;
                            <input class="btn" type="button" onclick="javascript:history.go(-1)" value="{:L('RETURN')}"/>
                        </td>
                    </tr>
                    </tfoot>
                    <tbody>
                    <tr>
                        <td width="15%" class="tdleft">
                            试吃客户名称：
                        </td>
                        <td>
                            {$customer['name']}
                        </td>
                        <td class="tdleft">
                            收货人姓名：
                        </td>
                        <td>
                            <input type="text" name="contact_name" value="" />
                        </td>
                    </tr>
                    <tr>
                        <td class="tdleft">
                            试吃收货地址：
                        </td>
                        <td colspan="3">
                            <script type="text/javascript">
                                $(function(){
                                    new PCAS("address['state']","address['city']","address['area']","","","");
                                });
                            </script><select name="address['state']" class="input-medium"><option value="">--请选择省份--</option><option value="北京市">北京市</option><option value="天津市">天津市</option><option value="河北省">河北省</option><option value="山西省">山西省</option><option value="内蒙古自治区">内蒙古自治区</option><option value="辽宁省">辽宁省</option><option value="吉林省">吉林省</option><option value="黑龙江省">黑龙江省</option><option value="上海市">上海市</option><option value="江苏省">江苏省</option><option value="浙江省">浙江省</option><option value="安徽省">安徽省</option><option value="福建省">福建省</option><option value="江西省">江西省</option><option value="山东省">山东省</option><option value="河南省">河南省</option><option value="湖北省">湖北省</option><option value="湖南省">湖南省</option><option value="广东省">广东省</option><option value="广西壮族自治区">广西壮族自治区</option><option value="海南省">海南省</option><option value="重庆市">重庆市</option><option value="四川省">四川省</option><option value="贵州省">贵州省</option><option value="云南省">云南省</option><option value="西藏自治区">西藏自治区</option><option value="陕西省">陕西省</option><option value="甘肃省">甘肃省</option><option value="青海省">青海省</option><option value="宁夏回族自治区">宁夏回族自治区</option><option value="新疆维吾尔自治区">新疆维吾尔自治区</option><option value="香港特别行政区">香港特别行政区</option><option value="澳门特别行政区">澳门特别行政区</option><option value="台湾省">台湾省</option><option value="其它">其它</option></select>
                            <select name="address['city']" class="input-medium"><option value="">全部</option><option value="">--请选择城市--</option></select>
                            <select name="address['area']" class="input-medium"><option value="">全部</option><option value="">--请选择地区--</option></select>
                            <input name="address['street']" placeholder="街道信息" class="input-large" value="" type="text">
                        </td>
                    </tr>
                    <tr>
                        <td class="tdleft">
                            收货人联系电话：
                        </td>
                        <td>
                            <input type="text" name="phone_number" value="" />
                        </td>
                        <td class="tdleft">
                            试吃人数：
                        </td>
                        <td>
                            <input type="text" name="taster_num" value="" />
                        </td>
                    </tr>
                    <tr>
                        <td class="tdleft">
                            试吃商品名称：
                        </td>
                        <td id="zzr_ad">
                            <input type="text" name="product" value="" />
                            <!--<div id="cake0"class="product_name">-->
                            <!--<select id="cake_sel0" name="cakename[]" onchange="get_bou(this,0);">-->
                                    <!--<option   value="{$key}">请选择</option>-->
                                <!--<foreach name="good_list" item="vo" key="key">-->
                                    <!--<option emoney="{$key}" value="{$vo.goods_name}">{$vo.goods_name}</option>-->
                                <!--</foreach>-->
                            <!--</select>-->
                            <!--<select  name="cake_b[]"id="bun0">-->
                                <!--<option value="{$key}">请选择</option>-->
                            <!--</select>-->
                            <!--数量：<input style="width: 30px" type="text" name="cake_num[]" value="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span onclick="add_cake()"style="color: green">继续添加</span>-->
                            <!--</div>-->

                        </td>
                        <td class="tdleft">
                            配送时间：
                        </td>
                        <td>
                            <input type="text" name="delivery_time" value="" onclick="WdatePicker({dateFmt:'yyyy-MM-dd HH:mm'})" />
                        </td>
                    </tr>
                    <tr>
                        <td class="tdleft">
                            物料需求：
                        </td>
                        <td>
                            <input type="text" name="materiel_support" value="" />
                        </td>
                    </tr>
                    <tr>
                        <td class="tdleft">
                            试吃原因：
                        </td>
                        <td colspan="3">
                            <textarea name="reason" class="span6" rows="6"></textarea>
                        </td>
                    </tr>
                    <tr>
                        <td class="tdleft">
                            备注：
                        </td>
                        <td colspan="3">
                            <textarea name="memo" class="span6" rows="6"></textarea>
                        </td>
                    </tr>

                    </tbody>
                </table>
            </form>
        </div>
    </div>
</div>
<div class="hide" id="dialog-validate" title="{:L('TEST_RESULTS')}">
    {:L('HAVE_THE_FOLLOWING_PRODUCTS_ARE_SIMILAR_TO_THE_PRODUCT_NAME')}
    <div id="search_content"></div>
</div>
<script type="text/javascript" src="__PUBLIC__/js/uploadPreview.js"></script>
<script type="text/javascript">

    function get_bou(obj,float){
        var num = $("#cake_sel"+float).find("option:selected").attr("emoney");
        var arr1 = <?php echo json_encode($good_list) ?>;
        $("#bun"+float).empty();
            var selectObj=document.getElementById("bun"+float);
            for (var i=0;i<arr1[num]["attra"].length;i++)
            {
                selectObj.options[selectObj.length] = new Option(arr1[num]["attra"][i]["attr_name"], arr1[num]["attra"][i]["attr_name"]);
            }

    }
    var i = 0;
    function  add_cake(){
        i++;
        var sd = i-2;

        var str = "<div id='cake"+sd+"'class='product_name'><select id='cake_sel"+sd+"' name='cakename[]' onchange='get_bou(this,"+sd+")'> <option value='{$key}'>请选择</option><foreach name='good_list' item='vo' key='key'><option emoney='{$key}'value='{$vo.goods_name}'>{$vo.goods_name}</option> </foreach> </select> <select id='bun"+sd+"' name='cake_b[]'> <option value='{$key}'>请选择</option> </select>  数量：<input style='width: 30px' type='text' id='cake_num"+sd+"' value='' name='cake_num[]' />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style='color: red;' onclick='del_cake("+sd+")'>删除</span> </div>";
        $("#zzr_ad").append(str);
    }
    function del_cake(num){
        $("#cake"+num).empty();
    }
    //初始化上传图片
    $("body").on('click','input[type="file"]', function(){
        var selector = $(this).attr('id');
        $("#"+selector).uploadPreview({ Img: selector+"_prev", Width: 120, Height: 120 });
    });

    $(function(){
        $('#name').blur(
                function(){
                    name = $('#name').val();
                    if(name!=''){
                        $.post('{:U("product/check")}',
                                {
                                    name:name
                                },
                                function(data){
                                    if(data.data != 0){
                                        $result = '';
                                        $.each(data.data, function(k, v){
                                            $result += (k+1)+'、'+v+'</br>';
                                        });
                                        $('#dialog-validate').dialog('open');
                                        $("#search_content").html($result);
                                    }
                                },
                                'json');
                    } else {
                        alert('{:L('PLEASE_FILL_OUT_THE_PRODUCT_NAME')}!');
                    }
                }
        )
        $("#dialog-validate").dialog({
            autoOpen: false,
            modal: true,
            width: 400,
            maxHeight: 400,
            buttons: {
                "{:L('CONFIRM')}": function () {
                    $(this).dialog("close");
                }
            },
            position: ["center", 100]
        });
        $('#validate').click(
                function(){
                    name = $('#name').val();
                    if(name!=''){
                        $.post('{:U("product/validate")}',
                                {
                                    name:name,
                                },
                                function(data){
                                    alert(data.info);
                                },
                                'json');
                    } else {
                        alert('{:L('PLEASE_FILL_OUT_THE_PRODUCT_NAME')}!');
                    }
                }
        );
        $('#remove').click(
                function(){
                    $('#owner_id').attr('value', '');
                    $('#owner_name').attr('value', '');
                }
        );
    });
    $(function(){
        $.formValidator.initConfig({formID:"form1",debug:false,submitOnce:true,
            onError:function(msg,obj,errorlist){
                alert(msg);
            },

        });
        <volist name="field_list[main]" id="vo">
            <if condition="$vo['is_validate'] == 1">
                <if condition="$vo['form_type'] != 'box' || $vo['setting']['type'] == 'select'">
                    $("#{$vo[field]}").formValidator({
                    tipID:"{$vo[field]}Tip",
                    <if condition="$vo['is_null'] == 1">
                    onShow:"<span style='color:red;'>{:L('WILL_OPTIONS')}</span>",
                    empty:false,
                    <else />
                    onShow:" ",
                    empty:true,
                    </if>
                    onFocus:" ",
                    onCorrect:"<span style='color:green;'>√</span>"
                }).inputValidator({
                    <if condition="$vo['is_null'] == 1">
                    min:1,max:{$vo[max_length]|default="255"},
                    onshow:"{:L('NOT NULL',array($vo[name]))}",
                    <else />
                    min:0,max:{$vo[max_length]|default="255"},
                    </if>
                    onErrorMin:"{:L('NOT NULL',array($vo[name]))}",
                    onErrorMax:"{:L('MAXIMUM_REQUEST_LENGTH_EXCEEDED',array($vo[name]))}"
                });
                    <if condition="$vo['form_type'] == 'email'">
                        $("#{$vo[field]}").regexValidator({
                        regExp:"email",
                        dataType:"enum",
                        onError:"{:L('A_OLUTE_OR_SELF_RELATIVE',array($vo[name]))}"
                    });
                        <elseif condition="$vo['form_type'] == 'mobile'"/>
                        $("#{$vo[field]}").regexValidator({
                        regExp:"mobile",
                        dataType:"enum",
                        onError:"{:L('A_OLUTE_OR_SELF_RELATIVE',array($vo[name]))}"
                    });
                        <elseif condition="$vo['form_type'] == 'phone'"/>
                        $("#{$vo[field]}").regexValidator({
                        regExp:"tel",
                        dataType:"enum",
                        onError:"{:L('A_OLUTE_OR_SELF_RELATIVE',array($vo[name]))}"
                    });
                        <elseif condition="$vo['form_type'] == 'datetime'"/>
                        $("#{$vo[field]}").regexValidator({
                        regExp:"date",
                        dataType:"enum",
                        onError:"{:L('A_OLUTE_OR_SELF_RELATIVE',array($vo[name]))}"
                    });
                        <elseif condition="$vo['form_type'] == 'number'"/>
                        $("#{$vo[field]}").regexValidator({
                        regExp:"num",
                        dataType:"enum",
                        onError:"{:L('A_OLUTE_OR_SELF_RELATIVE',array($vo[name]))}"
                    });
                    </if>
                    <if condition="$vo['is_unique'] == 1">
                        $("#{$vo[field]}").ajaxValidator({
                        dataType : "json",
                        type : "GET",
                        async : false,
                        url : "{:U('product/validate')}",
                        success : function(data){
                        if( data.status == 1 ) return false;
                        if( data.status == 0 ) return true;$("#form1").submit();
                        return false;
                    },
                        error: function(jqXHR, textStatus, errorThrown){alert("{:L('THE_SERVER_DID_NOT_RETURN_DATA_MAY_BE_THE_SERVER_BUSY_PLEASE_TRY_AGAIN')}"+errorThrown);},
                        onError : "{:L('THIS_DISABLED_PLEASE_CHANGE',array($vo[name],$vo[name]))}",
                        onWait : "{:L('LEGITIMACY_CHECKING_PLEASE_WAIT',array($vo[name]))}"
                    });
                    </if>
                    <else />
                    <if condition="$vo['setting']['type'] == 'checkbox'">
                        $(":checkbox[name='{$vo['field']}[]']").formValidator({
                        tipID:"{$vo[field]}Tip",
                        <if condition="$vo['is_null'] == 1">
                        onShow:"<span style='color:red;'>{:L('WILL_OPTIONS')}</span>",
                        <else />
                        onShow:" ",
                        </if>
                        onFocus:" ",
                        onCorrect:"<span style='color:green;'>√</span>"
                    }).inputValidator({
                        <if condition="$vo['is_null'] == 1">
                        min:1,
                        <else/>
                        min:0,
                        </if>
                        onError:"{:L('PLEASE_SELECT',array($vo[name]))}"
                    });
                        <elseif condition="$vo['setting']['type'] == 'select'"/>
                        $("#{$vo[field]}").formValidator({
                        tipID:"{$vo[field]}Tip",
                        <if condition="$vo['is_null'] == 1">
                        onShow:"<span style='color:red;'>{:L('WILL_OPTIONS')}</span>",
                        <else />
                        onShow:" ",
                        </if>
                        onFocus:" ",
                        onCorrect:"<span style='color:green;'>√</span>"
                    }).inputValidator({
                        <if condition="$vo['is_null'] == 1">
                        min:1,
                        <else/>
                        min:0,
                        </if>
                        onError:"{:L('PLEASE_SELECT',array($vo[name]))}"
                    });
                        <else />
                        $(":radio[name='{$vo['field']}']").formValidator({
                        tipID:"{$vo[field]}Tip",
                        <if condition="$vo['is_null'] == 1">
                        onShow:"<span style='color:red;'>{:L('WILL_OPTIONS')}</span>",
                        <else />
                        onShow:" ",
                        </if>
                        onFocus:" ",
                        onCorrect:"<span style='color:green;'>√</span>"
                    }).inputValidator({
                        <if condition="$vo['is_null'] == 1">
                        min:1,
                        <else/>
                        min:0,
                        </if>
                        onError:"{:L('PLEASE_SELECT',array($vo[name]))}"
                    });
                    </if>
                </if>
            </if>
        </volist>
        <volist name="field_list[data]" id="vo">
                <if condition="$vo['is_validate'] == 1">
                <if condition="$vo['form_type'] != 'box' || $vo['setting']['type'] == 'select'">
                $("#{$vo[field]}").formValidator({
                    tipID:"{$vo[field]}Tip",
            <if condition="$vo['is_null'] == 1">
                onShow:"<span style='color:red;'>{:L('WILL_OPTIONS')}</span>",
                empty:false,
                <else />
                onShow:" ",
                empty:true,
            </if>
        onFocus:" ",
                onCorrect:"<span style='color:green;'>√</span>"
    }).inputValidator({
        <if condition="$vo['is_null'] == 1">
            min:1,max:{$vo[max_length]|default="255"},
            onshow:"{:L('NOT NULL',array($vo[name]))}",
            <else />
            min:0,max:{$vo[max_length]|default="255"},
        </if>
        onErrorMin:"{:L('NOT NULL',array($vo[name]))}",
                onErrorMax:"{:L('MAXIMUM_REQUEST_LENGTH_EXCEEDED',array($vo[name]))}"
    });
        <if condition="$vo['form_type'] == 'email'">
            $("#{$vo[field]}").regexValidator({
            regExp:"email",
            dataType:"enum",
            onError:"{:L('A_OLUTE_OR_SELF_RELATIVE',array($vo[name]))}"
        });
            <elseif condition="$vo['form_type'] == 'mobile'"/>
            $("#{$vo[field]}").regexValidator({
            regExp:"mobile",
            dataType:"enum",
            onError:"{:L('A_OLUTE_OR_SELF_RELATIVE',array($vo[name]))}"
        });
            <elseif condition="$vo['form_type'] == 'phone'"/>
            $("#{$vo[field]}").regexValidator({
            regExp:"tel",
            dataType:"enum",
            onError:"{:L('A_OLUTE_OR_SELF_RELATIVE',array($vo[name]))}"
        });
            <elseif condition="$vo['form_type'] == 'datetime'"/>
            $("#{$vo[field]}").regexValidator({
            regExp:"date",
            dataType:"enum",
            onError:"{:L('A_OLUTE_OR_SELF_RELATIVE',array($vo[name]))}"
        });
            <elseif condition="$vo['form_type'] == 'number'"/>
            $("#{$vo[field]}").regexValidator({
            regExp:"num",
            dataType:"enum",
            onError:"{:L('A_OLUTE_OR_SELF_RELATIVE',array($vo[name]))}"
        });
        </if>
        <if condition="$vo['is_unique'] == 1 && $vo['field']!='name'">
                $("#{$vo[field]}").ajaxValidator({
                    dataType : "json",
                    type : "GET",
                    async : false,
                    url : "{:U('product/validate')}",
                    success : function(data){
                        if( data.status == 1 ) return false;
                        if( data.status == 0 ) return true;$("#form1").submit();
                        return false;
                    },
                    error: function(jqXHR, textStatus, errorThrown){alert("{:L('THE_SERVER_DID_NOT_RETURN_DATA_MAY_BE_THE_SERVER_BUSY_PLEASE_TRY_AGAIN')}"+errorThrown);},
                    onError : "{:L('THIS_DISABLED_PLEASE_CHANGE',array($vo[name],$vo[name]))}",
                    onWait : "{:L('LEGITIMACY_CHECKING_PLEASE_WAIT',array($vo[name]))}"
                });
        </if>
        <else />
        <if condition="$vo['setting']['type'] == 'checkbox'">
            $(":checkbox[name='{$vo['field']}[]']").formValidator({
            tipID:"{$vo[field]}Tip",
            <if condition="$vo['is_null'] == 1">
            onShow:"<span style='color:red;'>{:L('WILL_OPTIONS')}</span>",
            <else />
            onShow:" ",
            </if>
            onFocus:" ",
            onCorrect:"<span style='color:green;'>√</span>"
        }).inputValidator({
            <if condition="$vo['is_null'] == 1">
            min:1,
            <else/>
            min:0,
            </if>
            onError:"{:L('PLEASE_SELECT',array($vo[name]))}"
        });
            <elseif condition="$vo['setting']['type'] == 'select'"/>
            $("#{$vo[field]}").formValidator({
            tipID:"{$vo[field]}Tip",
            <if condition="$vo['is_null'] == 1">
                onShow:"<span style='color:red;'>{:L('WILL_OPTIONS')}</span>",
                <else />
                onShow:" ",
            </if>
            onFocus:" ",
            onCorrect:"<span style='color:green;'>√</span>"
            }).inputValidator({
            <if condition="$vo['is_null'] == 1">
                min:1,
                <else/>
                min:0,
            </if>
            onError:"{:L('PLEASE_SELECT',array($vo[name]))}"
            });
            <else />
            $(":radio[name='{$vo['field']}']").formValidator({
            tipID:"{$vo[field]}Tip",
            <if condition="$vo['is_null'] == 1">
                onShow:"<span style='color:red;'>{:L('WILL_OPTIONS')}</span>",
                <else />
                onShow:" ",
            </if>
            onFocus:" ",
            onCorrect:"<span style='color:green;'>√</span>"
            }).inputValidator({
            <if condition="$vo['is_null'] == 1">
                min:1,
                <else/>
                min:0,
            </if>
            onError:"{:L('PLEASE_SELECT',array($vo[name]))}"
            });
        </if>
        </if>
        </if>
        </volist>
        });
</script>
<include file="Public:footer" />
